package com.itheima.file.controller.v1;

import com.itheima.file.service.FileService;
import com.itheima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
@RequestMapping("/api/v1")
@Api(value = "文件相关的接口", tags = "文件相关的接口")
public class FileController {

    @Autowired
    private FileService fileService;

    /**
     * 单文件上传
     */
    @PostMapping("/file")
    @ApiOperation("上传单个文件")
    public ResponseResult uploadFile(MultipartFile file) {
       return fileService.uploadFile(file);
    }

    /**
     * 批量文件上传
     */
    @PostMapping("/files")
    @ApiOperation("批量上传文件")
    public ResponseResult uploadFiles(MultipartFile[] files) {
        return fileService.uploadFiles(files);
    }

    /**
     * 删除文件
     */
    @DeleteMapping("/file")
    @ApiOperation("删除文件")
    public ResponseResult deleteFile(String fileUrl) {
        return fileService.deleteFile(fileUrl);
    }
}